
import java.util.HashMap;
import java.util.List;
import java.io.*;
import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.common.Term;

public class LoadThenTest {
    public static boolean isCN(char c) {
        return String.valueOf(c).matches("[\u4e00-\u9fa5]");
    }

    public static void main(String[] args) {
        FileReader ftest = null;
        BufferedReader bf = null;
        String line = new String();

        Pack p = new Pack(new HashMap<String, Integer>(), 0, 0, 0);
        try {
            ftest = new FileReader("hmap.txt");
            bf = new BufferedReader(ftest);

            while ((line = bf.readLine()) != null) {
                int id = line.indexOf('#');
                String stmp = line.substring(0, id);
                String itmp = line.substring(id + 1, line.length());
                p.hm.put(stmp, Integer.parseInt(itmp));
            }
            System.out.print(p.hm.size());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                ftest.close();
                bf.close();
            } catch (Exception e) {
                ;
            }
        }
        int cntwords = 0;
        try {
            StringBuffer pathname = new StringBuffer("./");
            while (true) {
                ftest = new FileReader(pathname + "test3.txt");
                bf = new BufferedReader(ftest);
                while ((line = bf.readLine()) != null) {
                    System.out.println(line);

                    StringBuffer parsed = new StringBuffer("u," + line + ".V");
                    for (int i = 2; parsed.charAt(i) != '.' && parsed.charAt(i) != 'V'; i++) {
                        if (!isCN(parsed.charAt(i))) {
                            if (i == 2 || i == parsed.length() - 3) {
                                parsed.delete(i, i + 1);
                                continue;
                            }
                            parsed.replace(i, i + 1, ".Vu,");
                            i += 3;
                        }
                    }
                    line = new String(parsed);
                    // System.out.println(line);
                    List<Term> termList = HanLP.segment(line);
                    cntwords += termList.size();
                    int id = 0;
                    /*
                     * for (; id < termList.size() - 1; id++) { Term ant = termList.get(id); Term
                     * pos = termList.get(id + 1);
                     * 
                     * String cat = ant.word + pos.word; if (Multithread.containNCN(ant.word) ||
                     * Multithread.containNCN(pos.word)) continue; // System.out.print(ant.word +
                     * " " + pos.word + " "); double count1 = 0.00001 * p.cnt2 + 1, count2 = 0.1;
                     * double count1r = count1; if (p.hm.containsKey(ant.word)) count1 +=
                     * Math.log(p.hm.get(ant.word)); if (p.hm.containsKey(cat)) count2 +=
                     * p.hm.get(cat); if (p.hm.containsKey(pos.word)) count1r +=
                     * Math.log(p.hm.get(pos.word)); double score1 = Math.log(count2 / count1);
                     * double score2 = Math.log(count2 / count1r); if (score1 < -4 || score2 < -4) {
                     * System.out.println(cat + " | " + ant.word + " " + score1);
                     * System.out.println(cat + " | " + pos.word + " " + score2); } }
                     */
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                ftest.close();
                bf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}